package com.zc.iotDevice.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.iotDevice.domain.ChargeFault;
import com.zc.iotDevice.service.IChargeFaultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 故障报修Controller
 *
 * @author glb
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/iotDevice/fault")
public class ChargeFaultController extends BaseController
{
    @Autowired
    private IChargeFaultService chargeFaultService;

    /**
     * 查询故障报修列表
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeFault chargeFault)
    {
        startPage();
        List<ChargeFault> list = chargeFaultService.selectChargeFaultList(chargeFault);
        return getDataTable(list);
    }

    /**
     * 导出故障报修列表
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:export')")
    @Log(title = "故障报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeFault chargeFault)
    {
        List<ChargeFault> list = chargeFaultService.selectChargeFaultList(chargeFault);
        ExcelUtil<ChargeFault> util = new ExcelUtil<>(ChargeFault.class);
        util.exportExcel(response, list, "故障报修数据");
    }

    /**
     * 获取故障报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:query')")
    @GetMapping(value = "/{deviceFaultId}")
    public AjaxResult getInfo(@PathVariable("deviceFaultId") Long deviceFaultId)
    {
        return AjaxResult.success(chargeFaultService.selectChargeFaultByDeviceFaultId(deviceFaultId));
    }

    /**
     * 新增故障报修
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:add')")
    @Log(title = "故障报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeFault chargeFault)
    {
        return toAjax(chargeFaultService.insertChargeFault(chargeFault));
    }

    /**
     * 修改故障报修
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:edit')")
    @Log(title = "故障报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeFault chargeFault)
    {
        return toAjax(chargeFaultService.updateChargeFault(chargeFault));
    }

    /**
     * 删除故障报修
     */
    @PreAuthorize("@ss.hasPermi('iotDevice:fault:remove')")
    @Log(title = "故障报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceFaultIds}")
    public AjaxResult remove(@PathVariable Long[] deviceFaultIds)
    {
        return toAjax(chargeFaultService.deleteChargeFaultByDeviceFaultIds(deviceFaultIds));
    }
}
